package com.hfy.music.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hfy.model.dto.AlbumDto;
import com.hfy.model.po.music.AlbumPo;
import com.hfy.model.po.music.AlbumStylePo;
import com.hfy.model.vo.AlbumVo;
import com.hfy.music.mapper.AlbumMapper;
import com.hfy.music.service.AlbumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import result.Result;

import java.util.List;

/**
 * @ author 韩
 * time: 2024/7/17 14:54
 */
@Service
public class AlbumServiceImpl extends ServiceImpl<AlbumMapper, AlbumPo> implements AlbumService  {

    @Autowired
    private AlbumMapper albumMapper;

    @Override
    public Result addAlbum(AlbumDto dto) {
        // 本方法逻辑就是向数据库里查询一条专辑信息
        // 1. 校验参数
        boolean isEmpty = BeanUtil.isEmpty(dto);
        if (isEmpty) return Result.error("专辑信息不能为空");
        albumMapper.insertAlbum(dto);
        return Result.ok();
    }

    @Override
    public Result getAlbums(Long account) {
        if (account == null) return Result.error("账号不许为空");

        List<AlbumVo> albums = albumMapper.getAlbums(account);
        return Result.ok(albums);
    }

    @Override
    public Result listAlbumStyles() {

        AlbumStylePo stylePo = new AlbumStylePo();
        List<AlbumStylePo> styles = stylePo.selectAll();
        return Result.ok(styles);
    }
}
